// callFunction
'use strict';
module.exports = {
	// __before调用其他方法前会先调用这个方法
	_before(context) {
		// 创建实人认证实例
		this.frvManager = uniCloud.getFacialRecognitionVerifyManager({
			requestId: this.getUniCloudRequestId()
		})
	},
	/**
	 * 获取certifyId
	 * @param realName 姓名
	 * @param idCard 身份证号
	 * @param metaInfo  uni.getFacialRecognitionMetaInfo()获取的
	 */
	async getCertifyId({
		realName,
		idCard,
		metaInfo
	}) {
		// 会先调用_before
		try {
			const result = await this.frvManager.getCertifyId({
				realName,
				idCard,
				metaInfo
			});
			return result
		} catch (e) {
			return {
				errCode: 500,
				message: '获取CertifyId失败'
			};
		}
	},
	/**
	 * 获取认证的结果
	 */
	async getAuthResult(certifyId) {
		try {
			const result = await this.frvManager.getAuthResult({
				certifyId
			});
			return result
		} catch (e) {
			return {
				errCode: 500,
				message: '获取认证失败'
			};
		}
	}
}